import flet
import time
from flet import AppBar, ElevatedButton, Page, Text, View, colors
import animate_opacity
import animate
import rotate
import card
import counter
import simple
import config_json
import getpath
import myglobal
myglobal.initpath=getpath.getpath()
config_json.read_setting()
import report
def main(page: Page):
    page.title = "Routes Example"
    print(dir(page))
    page.window_width=500
    page.window_height=700
    print("Initial route:", page.route)
    def route_change(e):
        print("Route change:", e.route)
        page.views.clear()
        page.views.append(
            View(
                "/",
                [
                    AppBar(title=Text("Flet app")),
                    ElevatedButton("report", on_click=lambda e: page.go("/report")),
                    ElevatedButton("animate", on_click=lambda e: page.go("/animate")),
                    ElevatedButton("animate_opacity", on_click=lambda e: page.go("/animate_opacity")),
                    ElevatedButton("rotate", on_click=lambda e: page.go("/rotate")),
                    ElevatedButton("card", on_click=lambda e: page.go("/card")),
                    ElevatedButton("counter", on_click=lambda e: page.go("/counter")),
                    ElevatedButton("simple", on_click=lambda e: page.go("/simple")),
                ],
            )
        )
        if page.route == "/animate":
            page.views.append(animate.animateView(page))
        elif page.route == "/animate_opacity":
            page.views.append(animate_opacity.mainView())
        elif page.route == "/rotate":
            page.views.append(rotate.rotateView(page))
        elif page.route == "/card":
            page.views.append(card.mainView(page)) 
        elif page.route == "/counter":
            page.views.append(counter.mainView(page))                          
        elif page.route == "/simple":
            page.views.append(simple.mainView(page))                                  
        elif page.route == "/report":
            mainw=report.MainW()
            page.views.append(mainw.mainView(page))                           
        page.update()
    def view_pop(e):
        print("View pop:", e.view)
        page.views.pop()
        top_view = page.views[-1]
        page.go(top_view.route)
    page.on_route_change = route_change
    page.on_view_pop = view_pop
    page.go(page.route)


flet.app(target=main)#, view=flet.WEB_BROWSER)
